package array;

import java.util.Arrays;

public class leetCode287_findDuplicate {
    public int findDuplicate(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int slow = 0;
        int fast = 0;
        slow = nums[slow];
        fast = nums[nums[fast]];
        while (slow != fast){
            fast = nums[nums[fast]];
            slow = nums[slow];
        }
        slow = 0;
        while (fast != slow){
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;

    }
}
